﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

namespace WinFormClient
{
    enum Intefaces
    {
        IWho = 0,
        IData = 1
    }

    internal static class Attributes
    {
        
        public static string GetName<T>(this string enumValue)
        {
            Type t = typeof(T);
            if (!t.IsEnum) return "";

            return "," +t.Name +"."+ Enum.GetName(t, int.Parse(enumValue));
        }
    }


    //********************************************************
    /// <summary>
    /// 關鍵欄位
    /// </summary>
    public class KeyFieldAttribute : Attribute
    { }

    /// <summary>
    /// 不能為空的欄位
    /// </summary>
    public class NotNullFieldAttribute : Attribute { }

    /// <summary>
    /// 用於檢索的欄位
    /// </summary>
    public class SearchFieldAttribute : Attribute
    {
        int _visibleIndex;
        DevGridControlType _devControlType;
        CompareType _compare = CompareType.like;

        /// <summary>
        /// 顯示位置
        /// </summary>
        public int VisibleIndex
        {
            get { return _visibleIndex; }
        }

        /// <summary>
        /// 表現的控件類型
        /// </summary>
        public DevGridControlType DevControlType
        {
            get { return _devControlType; }
        }

        /// <summary>
        /// 比較類型
        /// </summary>
        public CompareType Compare
        {
            get { return _compare; }
        }

        /// <summary>
        /// 實例化
        /// </summary>
        /// <param name="visibleIndex">顯示位置</param>
        /// <param name="devControlType">顯示控件類型</param>
        /// <param name="compare">比較類型</param>
        public SearchFieldAttribute(int visibleIndex, DevGridControlType devControlType, CompareType compare)
        {
            _visibleIndex = visibleIndex;
            _devControlType = devControlType;
            _compare = compare;
        }


        /// <summary>
        /// 實例化(compare = CompareType.like,如果devControlType=DevGridControlType.ComboBox,compare = CompareType.equal)
        /// </summary>
        /// <param name="visibleIndex">顯示位置</param>
        /// <param name="devControlType">顯示控件類型</param>
        public SearchFieldAttribute(int visibleIndex, DevGridControlType devControlType)
        {
            _visibleIndex = visibleIndex;
            _devControlType = devControlType;
            if (devControlType == DevGridControlType.ComboBox) _compare = CompareType.equal;
        }

        /// <summary>
        /// 實例化(compare = CompareType.like)
        /// </summary>
        /// <param name="visibleIndex">顯示位置</param>
        public SearchFieldAttribute(int visibleIndex)
        {
            _visibleIndex = visibleIndex;
        }

        /// <summary>
        /// 實例化(visibleIndex = 1,compare = CompareType.like)
        /// </summary>
        public SearchFieldAttribute()
        {
            _visibleIndex = 1;
        }
    }

    /// <summary>
    /// 綁定欄位
    /// </summary>
    public class BoundFieldAttribute : Attribute
    {
        int _visibleIndex;
        DevGridControlType _devControlType;
        Visibilities _visibility = Visibilities.None;
        Editable _editable = Editable.None;
        string _spinEditFormat = "0";
        int _maxLength = int.MaxValue;

        /// <summary>
        /// 實例化(maxLength = int.MaxValue)
        /// </summary>
        /// <param name="visibleIndex">顯示位置</param>
        /// <param name="devControlType">顯示控件類型</param>
        /// <param name="visibility">顯示屬性</param>
        /// <param name="editable">編輯屬性</param>
        /// <param name="spinEditFormat">spin格式化</param>
        public BoundFieldAttribute(int visibleIndex, DevGridControlType devControlType, Visibilities visibility, Editable editable, string spinEditFormat)
        {
            _visibleIndex = visibleIndex;
            _devControlType = devControlType;
            _visibility = visibility;
            _editable = editable;
            _spinEditFormat = spinEditFormat;
        }

        /// <summary>
        /// 實例化
        /// </summary>
        /// <param name="visibleIndex">顯示位置</param>
        /// <param name="devControlType">顯示控件類型</param>
        /// <param name="visibility">顯示屬性</param>
        /// <param name="editable">編輯屬性</param>
        /// <param name="spinEditFormat">spin格式化</param>
        /// <param name="maxLength">最大長度</param>
        public BoundFieldAttribute(int visibleIndex, DevGridControlType devControlType, Visibilities visibility, Editable editable, string spinEditFormat, int maxLength)
        {
            _visibleIndex = visibleIndex;
            _devControlType = devControlType;
            _visibility = visibility;
            _editable = editable;
            _spinEditFormat = spinEditFormat;
            _maxLength = maxLength;
        }

        /// <summary>
        /// 實例化(spinEditFormat=0)
        /// </summary>
        /// <param name="visibleIndex">顯示位置</param>
        /// <param name="devControlType">顯示控件類型</param>
        /// <param name="visibility">顯示屬性</param>
        /// <param name="editable">編輯屬性</param>
        /// <param name="maxLength">最大長度</param>
        public BoundFieldAttribute(int visibleIndex, DevGridControlType devControlType, Visibilities visibility, Editable editable, int maxLength)
        {
            _visibleIndex = visibleIndex;
            _devControlType = devControlType;
            _visibility = visibility;
            _editable = editable;
            _maxLength = maxLength;
        }

        /// <summary>
        /// 實例化(spinEditFormat=0,maxLength = int.MaxValue)
        /// </summary>
        /// <param name="visibleIndex">顯示位置</param>
        /// <param name="devControlType">顯示控件類型</param>
        /// <param name="visibility">顯示屬性</param>
        /// <param name="editable">編輯屬性</param>
        public BoundFieldAttribute(int visibleIndex, DevGridControlType devControlType, Visibilities visibility, Editable editable)
        {
            _visibleIndex = visibleIndex;
            _devControlType = devControlType;
            _visibility = visibility;
            _editable = editable;
        }

        /// <summary>
        /// 實例化(spinEditFormat=0,visibility=Visibilities.List,editable = Editable.Enable,maxLength = int.MaxValue)
        /// </summary>
        /// <param name="visibleIndex">顯示位置</param>
        /// <param name="devControlType">顯示控件類型</param>
        public BoundFieldAttribute(int visibleIndex, DevGridControlType devControlType)
        {
            _visibleIndex = visibleIndex;
            _devControlType = devControlType;
            _visibility = Visibilities.List;
            _editable = Editable.Enable;
        }

        /// <summary>
        /// 實例化(spinEditFormat=0,editable = Editable.Enable,maxLength = int.MaxValue)
        /// </summary>
        /// <param name="visibleIndex">顯示位置</param>
        /// <param name="devControlType">顯示控件類型</param>
        /// <param name="visibility">顯示屬性</param>
        public BoundFieldAttribute(int visibleIndex, DevGridControlType devControlType, Visibilities visibility)
        {
            _visibleIndex = visibleIndex;
            _visibility = visibility;
            _devControlType = devControlType;
            _editable = Editable.Enable;
        }

        /// <summary>
        /// 實例化(spinEditFormat=0,devControlType=DevGridControlType.Text,editable = Editable.Enable,maxLength = int.MaxValue)
        /// </summary>
        /// <param name="visibleIndex">顯示位置</param>
        /// <param name="visibility">顯示屬性</param>
        public BoundFieldAttribute(int visibleIndex, Visibilities visibility)
        {
            _visibleIndex = visibleIndex;
            _visibility = visibility;
            _devControlType = DevGridControlType.Text;
            _editable = Editable.Enable;
        }

        /// <summary>
        /// 實例化(spinEditFormat=0,devControlType=DevGridControlType.Text,visibility = Visibilities.List,maxLength = int.MaxValue)
        /// </summary>
        /// <param name="visibleIndex">顯示位置</param>
        /// <param name="editable">編輯屬性</param>
        public BoundFieldAttribute(int visibleIndex, Editable editable)
        {
            _visibleIndex = visibleIndex;
            _visibility = Visibilities.List;
            _editable = editable;
            _devControlType = DevGridControlType.Text;
        }

        /// <summary>
        /// 實例化(spinEditFormat=0,visibility = Visibilities.List,maxLength = int.MaxValue)
        /// </summary>
        /// <param name="visibleIndex">顯示位置</param>
        /// <param name="devControlType">顯示控件類型</param>
        /// <param name="editable">編輯屬性</param>
        public BoundFieldAttribute(int visibleIndex, DevGridControlType devControlType, Editable editable)
        {
            _visibleIndex = visibleIndex;
            _visibility = Visibilities.List;
            _editable = editable;
            _devControlType = devControlType;
        }

        /// <summary>
        /// 實例化(devControlType = DevGridControlType.SpinEdit,editable = Editable.Enable,visibility = Visibilities.List,maxLength = int.MaxValue)
        /// </summary>
        /// <param name="visibleIndex">顯示位置</param>
        /// <param name="spinEditFormat">spin格式化</param>
        public BoundFieldAttribute(int visibleIndex, string spinEditFormat)
        {
            _visibleIndex = visibleIndex;
            _devControlType = DevGridControlType.SpinEdit;
            _spinEditFormat = spinEditFormat;
            _visibility = Visibilities.List;
            _editable = Editable.Enable;
        }

        /// <summary>
        /// 實例化(devControlType = DevGridControlType.SpinEdit,editable = Editable.Enable,visibility = Visibilities.List,maxLength = int.MaxValue)
        /// </summary>
        /// <param name="visibleIndex">顯示位置</param>
        /// <param name="devControlType">顯示控件類型</param>
        /// <param name="spinEditFormat">spin格式化</param>
        public BoundFieldAttribute(int visibleIndex, DevGridControlType devControlType, string spinEditFormat)
        {
            _visibleIndex = visibleIndex;
            _devControlType = devControlType;
            _spinEditFormat = spinEditFormat;
            _visibility = Visibilities.List;
            _editable = Editable.Enable;
        }

        /// <summary>
        /// 實例化(devControlType = DevGridControlType.Text,editable = Editable.Enable,visibility = Visibilities.List,maxLength = int.MaxValue)
        /// </summary>
        /// <param name="visibleIndex">顯示位置</param>
        public BoundFieldAttribute(int visibleIndex)
        {
            _visibleIndex = visibleIndex;
            _devControlType = DevGridControlType.Text;
            _visibility = Visibilities.List;
            _editable = Editable.Enable;

        }

        /// <summary>
        /// 實例化(devControlType = DevGridControlType.Text,editable = Editable.Enable,visibility = Visibilities.List)
        /// </summary>
        /// <param name="visibleIndex">顯示位置</param>
        /// <param name="maxLength">最大長度</param>
        public BoundFieldAttribute(int visibleIndex, int maxLength)
        {
            _visibleIndex = visibleIndex;
            _devControlType = DevGridControlType.Text;
            _visibility = Visibilities.List;
            _editable = Editable.Enable;
            _maxLength = maxLength;
        }

        /// <summary>
        /// 顯示位置
        /// </summary>
        public int VisibleIndex
        {
            get { return _visibleIndex; }
        }

        /// <summary>
        /// 編輯時的控件類型
        /// </summary>
        public DevGridControlType DevControlType
        {
            get { return _devControlType; }
        }

        /// <summary>
        /// 顯示特性
        /// </summary>
        public Visibilities Visibility
        {
            get { return _visibility; }
        }

        /// <summary>
        /// 編輯特性
        /// </summary>
        public Editable Edit
        {
            get { return _editable; }
        }

        /// <summary>
        /// Spin特性
        /// </summary>
        public string SpinEditFormat
        {
            get { return _spinEditFormat; }
        }

        /// <summary>
        /// 最大長度
        /// </summary>
        public int MaxLength
        {
            get { return _maxLength; }
        }
    }

    /// <summary>
    /// 顯示特性
    /// </summary>
    public enum Visibilities : int
    {
        /// <summary>
        /// 不顯示
        /// </summary>
        None = 0,
        /// <summary>
        /// 顯示在List中
        /// </summary>
        List = 1,
        /// <summary>
        /// 顯示在PreviewTemplate中
        /// </summary>
        Preview = 2,
        /// <summary>
        /// 顯示在PreviewTemplate中,并合併3欄
        /// </summary>
        PreviewColSpan3 = 3,
        /// <summary>
        /// 顯示在DetailTemplate中
        /// </summary>
        Detail = 4,
        /// <summary>
        /// 顯示在DetailTemplate中,并合併3欄
        /// </summary>
        DetailColSpan3 = 5
    }

    /// <summary>
    /// 編輯特性
    /// </summary>
    public enum Editable : int
    {
        /// <summary>
        /// 不可編輯
        /// </summary>
        None = 0,
        /// <summary>
        /// 編輯
        /// </summary>
        Enable = 1,
        /// <summary>
        /// 顯示為Password模式
        /// </summary>
        Password = 2,
        /// <summary>
        /// 合併3欄
        /// </summary>
        ColSpan3 = 3,
        /// <summary>
        /// 合併2行
        /// </summary>
        RowSpan2 = 4
    }

    /// <summary>
    /// 顯示控件類型
    /// </summary>
    public enum DevGridControlType : int
    {
        /// <summary>
        /// 單行文本
        /// </summary>
        Text = 0,
        /// <summary>
        /// 日期
        /// </summary>
        Date = 1,
        /// <summary>
        /// spinEdit
        /// </summary>
        SpinEdit = 2,
        /// <summary>
        /// combox
        /// </summary>
        ComboBox = 3,
        /// <summary>
        /// 多行文本
        /// </summary>
        Memo = 4,
        /// <summary>
        /// checkbox
        /// </summary>
        Check = 5,
        /// <summary>
        /// button
        /// </summary>
        ButtonEdit = 6,
        /// <summary>
        /// 超鏈接
        /// </summary>
        HyperLink = 7
    }

    /// <summary>
    /// 檢索條件的比較方式
    /// </summary>
    public enum CompareType : int
    {
        /// <summary>
        /// 等於
        /// </summary>
        equal = 0,
        /// <summary>
        /// like
        /// </summary>
        like = 1,
        /// <summary>
        /// 小於或等於
        /// </summary>
        equalLess = 2,
        /// <summary>
        /// 大於或等於
        /// </summary>
        equalAbove = 3
    }
    //********************************************************
}
